import 'package:flutter/material.dart';

import '../utils/callbacks.dart';

class CountBoard extends StatefulWidget {
  final String title;
  final String count;
  final VoidCallbackOneString? onClick;
  final Color titleColor;
  final Color countColor;
  const CountBoard(
      {super.key,
      required this.title,
      required this.count,
      required this.countColor,
      required this.titleColor,
      this.onClick});

  @override
  State<StatefulWidget> createState() => CountBoardState();
}

class CountBoardState extends State<CountBoard> {
  Widget _buildBoard() {
    return Material(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
      clipBehavior: Clip.antiAlias,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Material(
            color: widget.titleColor,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(5, 3, 3, 3),
              child: Text(
                widget.title,
                style: TextStyle(
                    color: widget.titleColor.value > Colors.red.value
                        ? Colors.black
                        : Colors.white),
              ),
            ),
          ),
          Material(
            color: widget.countColor,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(3, 3, 5, 3),
              child: Text(widget.count,
                  style: TextStyle(
                      color: widget.countColor.value > Colors.red.value
                          ? Colors.black
                          : Colors.white)),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return widget.onClick == null
        ? _buildBoard()
        : InkWell(
            onTap: () {
              widget.onClick?.call(widget.title);
            },
            child: _buildBoard(),
          );
  }
}
